export const User = {
  state: {
    user: {
      // id: '1001',
      // username: '饭饭',
      // headerimg: 'https://img2.baidu.com/it/u=2859542338,3761174075&fm=253&fmt=auto&app=138&f=JPEG?w=501&h=500',
      // desc: '这是我的个人简介噢',
    }
  },
  mutations: {
    SETNAME(state, username) {
      state.user.username = username
    },
    SETDESC(state, desc) {
      state.user.desc = desc
    },
    SAVE_USER(state, user) {
      console.log('vuex接受usr',user);
      let newUser = {
        id: user.uid,
        username: user.username,
        headerimg: 'https://img2.baidu.com/it/u=2859542338,3761174075&fm=253&fmt=auto&app=138&f=JPEG?w=501&h=500',
        desc: '这是我的个人简介噢',
      }
      state.user = newUser
    },
    REMOVE_USER(state){
      console.log('vuex清空用户');
      let newUser = {
        id: '',
        username: '',
        headerimg: 'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fi.qqkou.com%2Fi%2F1a3626475345x3078425090b26.jpg&refer=http%3A%2F%2Fi.qqkou.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1659239163&t=ea5d9b8cc8e72679551f29caf9cac366&qq-pf-to=pcqq.group',
        desc: '主人太懒了，什么都没留下',
      }
      state.user = newUser
    }
  },
  actions: {
    setName({
      commit
    }, username) {
      commit('SETNAME', username)
    },
    setDesc({
      commit
    }, desc) {
      commit('SETDESC', desc)
    },
    saveUser({
      commit
    }, user) {
      commit('SAVE_USER', user)
    },
    removeUser({commit}){
      commit('REMOVE_USER')
    }
  }
}
